define(function (require, exports, module) {
    return function (jQuery) {
        (function ($) {
            var dateFormat = function (date, fmt) { //author: meizz
                var o = {
                    "M+": date.getMonth() + 1,                 //月份
                    "d+": date.getDate(),                    //日
                    "h+": date.getHours(),                   //小时
                    "m+": date.getMinutes(),                 //分
                    "s+": date.getSeconds(),                 //秒
                    "q+": Math.floor((date.getMonth() + 3) / 3), //季度
                    "S": date.getMilliseconds()             //毫秒
                };
                if (/(y+)/.test(fmt))
                    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt))
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            var defaultstarttime = new Date(new Date().setDate(new Date().getDate() - 7));
            var defaultendtime = new Date(new Date().setDate(new Date().getDate() - 1));


            var hotPointNetCtrl = function ($scope, httpservice) {
                //$scope.starttime1 = dateFormat(defaultendtime,'yyyy-MM-dd');
                //$scope.endtime1 = dateFormat(defaultendtime,'yyyy-MM-dd');
                //$scope.starttime2 = dateFormat(defaultendtime,'yyyy-MM-dd');
                //$scope.endtime2 = dateFormat(defaultendtime,'yyyy-MM-dd');

                $scope.keyword = "";
                $scope.indicator = "搜索次数";
                $scope.selectitems=[
                    {value:"searchcount",name:'搜索次数'},
                    {value:"usercount",name:'搜索用户数'}
                ];
                $scope.trend = $scope.selectitems[0];
                $scope.pct = $scope.selectitems[0];

                //删除下载文件
                $(".deletemodel").live("click",function(e){
                    var fileId = $(e.target).parent().attr("id");
                    if(confirm('你确定要删除该文件?')){
                        $.ajax({
                            url:httpservice.serverurl + "script/Common/DeleteTask",
                            type:"get",
                            data:{id:fileId},
                            dataType:"json",
                            success:function(result){
                                if(result.state){
                                    var condition = {
                                        mainmodule:"市场热点分析",
                                        submodule:"网络热点分析"
                                    }
                                    $scope.getDownloadList(condition);
                                    alert('删除成功!');
                                }
                                else{
                                    alert('删除失败!');
                                }
                            },
                            error:function(xmlHttpRequest,textStatus){
                                alert('请求出错!');
                            },
                            complete:function(xmlHttpRequest,textStatus){

                            }
                        });
                    }
                })

                var downloadoperate = function(cellvalue, options, rowObject){
                    var listprint = "<a class='viewmodel' href='javascript:'id='"+rowObject.id+"' title = '查看'><img src='../../../images/chakan.png' /></a>" +
                        "<a class='downloadmodel' style='margin: 0 15px;' href= '"+httpservice.downloadurl+""+rowObject.filename+".csv' target='_blank' id='"+rowObject.id+"' state='"+rowObject.status+"' title='下载'><img src='../../../images/download.png' /></a>" +
                        "<a class='deletemodel' href='javascript:' id='"+rowObject.id+"' state='"+rowObject.state+"' title='删除'><img src='../../../images/delete1.png' /></a>";
                    return listprint;
                };

                $scope.grid1 = {
                    gridpagedata:{
                        nowpage:1,
                        totalpage:1,
                        totalcount:20,
                        startline:1,
                        endline:20,
                        pagesize:20,
                        datacount:20,
                        pagelist:[20,50,100],
                        //第一页
                        toFirstpage: function(){
                            $scope.grid1.gridpagedata.nowpage=1;
                            $scope.turnPage1();
                        },
                        //上一页
                        toToppage: function(){
                            if($scope.grid1.gridpagedata.nowpage>1){
                                $scope.grid1.gridpagedata.nowpage--;
                            }
                            $scope.turnPage1();
                        },
                        //下一页
                        toNextpage: function(){
                            if($scope.grid1.gridpagedata.nowpage<$scope.grid1.gridpagedata.totalpage){
                                $scope.grid1.gridpagedata.nowpage++;
                            }
                            $scope.turnPage1();
                        },
                        //最后一页
                        toLastpage: function(){
                            $scope.grid1.gridpagedata.nowpage = $scope.grid1.gridpagedata.totalpage;
                            $scope.turnPage1();
                        },
                        //跳转到某一页
                        topage: function(){
                            if($scope.grid1.gridpagedata.nowpage<1)
                            {
                                $scope.grid1.gridpagedata.nowpage = 1;
                            }
                            if($scope.grid1.gridpagedata.nowpage>$scope.grid1.gridpagedata.totalpage){
                                $scope.grid1.gridpagedata.nowpage = $scope.grid1.gridpagedata.totalpage;
                            }
                            $scope.turnPage1();
                        },
                        //改变页面显示记录数
                        changePagesize: function(){
                            $scope.grid1.gridpagedata.nowpage = 1;
                            $scope.turnPage1();
                        }
                    },
                    griddata: {
                        colnames: ['排名','搜索关键字','搜索引擎','搜索次数','搜索用户数','日均搜索量',"日均用户数","昨天排名"],
                        colmodel: [
                            { name: 'ranking', index: 'ranking', sortable: false, sorttype: 'number', align:"center",hidden:true},
                            { name: 'keyword', index: 'keyword', sortable: false, align:"center"},
                            { name: 'searchengine', index: 'searchengine', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'searchnumber', index: 'searchnumber', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'usernumber', index: 'searchusernumber', sortable: true, sorttype: 'number',align:"center",hidden:true},
                            { name: 'daysearchnumber', index: 'daysearchnumber', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'dayusernumber', index: 'dayusernumber', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'rankingyesterday', index: 'rankingyesterday', sortable: false, align:"center"}
                        ],
                        data: [
//                            { ranking: "1",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:3},
//                            { ranking: "2",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:2},
//                            { ranking: "3",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:10},
//                            { ranking: "4",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:22},
//                            { ranking: "5",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:1},
//                            { ranking: "6",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:4},
//                            { ranking: "7",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:9},
//                            { ranking: "8",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:39},
//                            { ranking: "9",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:24},
//                            { ranking: "10",keyword: "关键字1", searchengine: "百度、搜狗", searchnumber:1000, "usernumber":1000, "daysearchnumber": 1000,dayusernumber:1000, rankingyesterday:40}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth($(window).width());
                        grid.setGridHeight($(window).height()-255);
                    }
                };

                $scope.grid2 = {
                    griddata: {
                        colnames: ['关键字','搜索次数','日均用户数'],
                        colmodel: [
                            { name: 'keyword', index: 'keyword', sortable: false, align:"center"},
                            { name: 'searchcount', index: 'searchcount', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'dayusercount', index: 'dayusercount', sortable: true, sorttype: 'number',align:"center"}
                        ],
                        data: [
//                            { keyword: "世界杯",searchcount: 23543, usercount: 8889},
//                            { keyword: "足球",searchcount: 45778, usercount: 10776}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth($(window).width());
                        grid.setGridHeight(150);
                    }
                };

                $scope.grid3 = {
                    griddata: {
                        colnames: ['日期','世界杯','足球','NBA','网球'],
                        colmodel: [
                            { name: 'date', index: 'date', sortable: false, align:"center"},
                            { name: 'WorldCup', index: 'WorldCup', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'football', index: 'football', sortable: true, sorttype: 'number',align:"center"},
                            { name: 'NBA', index: 'NBA', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'tennis', index: 'tennis', sortable: true, sorttype: 'number', align:"center"}
                        ],
                        data: [
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300},
//                            { date: "2014-10-01",WorldCup: 100, football: 370, NBA: 200, tennis: 300}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth($(window).width() *0.4);
                        grid.setGridHeight(300);
                    }
                };

                $scope.downloadList = {
                    gridpagedata:{
                        nowpage:1,
                        totalpage:1,
                        totalcount:20,
                        startline:1,
                        endline:20,
                        pagesize:20,
                        datacount:20,
                        pagelist:[20,50,100],
                        toFirstpage: function(){
                            $scope.downloadList1.gridpagedata.nowpage = 1;
                            $scope.turnPageWAPByType();
                        },
                        toToppage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage>1){
                                $scope.downloadList1.gridpagedata.nowpage--;
                            }
                            $scope.turnPageWAPByType();
                        },
                        toNextpage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage<$scope.downloadList1.gridpagedata.totalpage){
                                $scope.downloadList1.gridpagedata.nowpage++;
                            }
                            $scope.turnPageWAPByType();
                        },
                        toLastpage: function(){
                            $scope.downloadList1.gridpagedata.nowpage = $scope.downloadList1.gridpagedata.totalpage;
                            $scope.turnPageWAPByType();
                        },
                        topage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage<1){
                                $scope.downloadList1.gridpagedata.nowpage = 1;
                            }
                            if($scope.downloadList1.gridpagedata.nowpage>$scope.downloadList1.gridpagedata.totalpage){
                                $scope.downloadList1.gridpagedata.nowpage = $scope.downloadList1.gridpagedata.totalpage;
                            }
                            $scope.turnPageWAPByType();
                        },
                        changePagesize: function(){
                            $scope.downloadList1.gridpagedata.nowpage = 1;
                            $scope.turnPageWAPByType();
                        }
                    },
                    griddata: {
                        colnames: ['ID','下载文件名', '创建时间','主模块','子模块','应用名称', '下载状态', '操作'],
                        colmodel: [
                            { name: 'id', index: 'id', sortable: false, align:"center",hidden:true },
                            { name: 'filename', index: 'filename', sortable: false, align:"center" },
                            { name: 'createtime', index: 'createtime', sortable: false, align:"center" },
                            { name: 'mainmodule',width:100, index: 'mainmodule', sortable: false, align:"center"},
                            { name: 'submodule',width:100, index: 'submodule', sortable: false, align:"center"},
                            { name: 'appname',width:100, index: 'appname', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'status',width:100, index: 'status', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'operate', index: 'operate', sortable: false, align:"center",formatter:downloadoperate}
                        ],
                        data: [
                            { "filename": "微信", "mainmodule": 1000, "submodule":1000, "appname":1000, "createtime": 1000,"status":1000, "operate":1000}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth(800);
                        grid.setGridHeight(300);
                    }
                };

                $scope.dialogList={
                    title:"下载列表",
                    ok:function(){},
                    cancel:function(){}
                };

                $scope.showDownloadlist = function(){
                    $scope.dialogList.show();
                    var condition = {
                        mainmodule:"市场热点分析",
                        submodule:"网络热点分析"
                    }
                    $scope.getDownloadList(condition);
//                    setInterval(function(){
//                        $.ajax({
//                            url:httpservice.serverurl + "script/Common/GetTaskList",
//                            type:"post",
//                            data:JSON.stringify(condition),
//                            dataType:"json",
//                            success:function(result){
//                                $scope.downloadList.griddata.data = result.datas;
//                                $scope.$apply();
//                            },
//                            error:function(xmlHttpRequest,textStatus){
//                                alert("请求出错!");
//                            },
//                            complete:function(xmlhHttpRequest,textStatus){
//
//                            }
//                        });
//                    },500);
                }

                $scope.getDownloadList = function(postdata){
                    $.ajax({
                        url:httpservice.serverurl + "script/Common/GetTaskList",
                        type:"post",
                        data:JSON.stringify(postdata),
                        dataType:"json",
                        success:function(result){
                            $scope.downloadList.griddata.data = result.datas;
                            $scope.$apply();
                        },
                        error:function(xmlHttpRequest,textStatus){
                            alert("请求出错!");
                        },
                        complete:function(xmlhHttpRequest,textStatus){

                        }
                    });
                }

                $scope.highchartline = {
                    chartdata: {
                        chart: {
                            height: 360,
                            type: 'line'
                        },
                        title: {
                            text: '关键字走势'
                        },
                        xAxis: {
                            gridLineWidth: 1,
                            lineColor: '#000',
                            tickColor: '#000',
                            labels: {
                                rotation: -30,
                                align: 'right',
                                style: {
                                    fontFamily: '黑体',
                                    fontWeight: 'Bold'           //Times New Roman
                                }
                            },
                            categories: ['10月1日','10月2日','10月3日','10月4日','10月5日','10月6日','10月7日','10月8日','10月9日','10月10日','10月1日']
                        },
                        yAxis: {
                            minorTickInterval: 'auto',
                            lineColor: '#000',
                            lineWidth: 1,
                            tickWidth: 1,
                            tickColor: '#000',
                            title: {
                                text: '搜索次数'
                            }
                        },
                        plotOptions: {
                            series: {
                                showCheckbox: true,
                                selected: true
//                                point: {
//                                    events: {
//                                        click: function () {
//                                        }
//                                    }
//                                }
                            },
                            line: {
                                events: {
                                    checkboxClick: function (event) {
                                        if (event.checked == true) {
                                            this.show();
                                        }
                                        else {
                                            this.hide();
                                        }
                                    },
                                    legendItemClick: function (event) {//return false 即可禁用LegendIteml，防止通过点击item显示隐藏系列
                                        return false;
                                    }
                                }
                            }
                        },
                        tooltip: {
                            valueSuffix: '次'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                name: '世界杯',
//                                data: [700,720,790,720,770,820,800,820,860,870]
//                            },
//                            {
//                                name: '足球',
//                                data: [570,560,550,580,590,680,660,600,600,670]
//                            }, {
//                                name: 'NBA',
//                                data: [270,260,250,280,290,280,260,200,200,270]
//                            }, {
//                                name: '网球',
//                                data: [170,160,150,180,190,180,160,100,100,170]
//                            }
                        ]
                    },
                    obj: {}
                };

                $scope.highchartpie0 = {
                    chartdata: {
                        chart: {
                            type: 'pie',
                            height: 360,
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false
                        },
                        title: {
                            text: ''
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true
                                }
                            }
                        },
                        tooltip: {
                            pointFormat: '{series.name}{point.percentage:.1f}%'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                name:"关键字",
//                                data: [
//                                    {name:'有道搜索',y:58},
//                                    {name:'百度搜索',y:15},
//                                    {name:'必应搜索',y:12},
//                                    {name:'谷歌搜索',y:10},
//                                    {name:'360搜索',y:5}
//                                ]
//                            }
                        ]
                    },
                    obj: {}
                };

                $scope.highchartpie1 = {
                    chartdata: {
                        chart: {
                            type: 'pie',
                            height: 360,
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false
                        },
                        title: {
                            text: ''
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true
                                }
                            }
                        },
                        tooltip: {
                            pointFormat: '{series.name}{point.percentage:.1f}%'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                data: [
//                                    ['有道搜索',58],
//                                    ['百度搜索',15],
//                                    ['必应搜索',12],
//                                    ['谷歌搜索',10],
//                                    ['360搜索',5]
//                                ]
//                            }
                        ]
                    },
                    obj: {}
                };

                $scope.highchartpie2 = {
                    chartdata: {
                        chart: {
                            type: 'pie',
                            height: 360,
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false
                        },
                        title: {
                            text: ''
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true
                                }
                            }
                        },
                        tooltip: {
                            pointFormat: '{series.name}{point.percentage:.1f}%'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                data: [
//                                    ['有道搜索',58],
//                                    ['百度搜索',15],
//                                    ['必应搜索',12],
//                                    ['谷歌搜索',10],
//                                    ['360搜索',5]
//                                ]
//                            }
                        ]
                    },
                    obj: {}
                };

                $scope.highchartpie3 = {
                    chartdata: {
                        chart: {
                            type: 'pie',
                            height: 360,
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false,
                            options3d: {
                                enabled: true,
                                alpha: 45,
                                beta: 0
                            }
                        },
                        title: {
                            text: ''
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true
                                }
                            }
                        },
                        tooltip: {
                            pointFormat: '{series.name}{point.percentage:.1f}%'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                data: [
//                                    ['有道搜索',58],
//                                    ['百度搜索',15],
//                                    ['必应搜索',12],
//                                    ['谷歌搜索',10],
//                                    ['360搜索',5]
//                                ]
//                            }
                        ]
                    },
                    obj: {}
                };

                //添加关键字
                $scope.addkeyword = function(){
                    var i=$('.dis input').size();
                    if(i>=4){
                        alert("关键字不能超过4个!");
                        return false;
                    }
                    $(".dis").append("<input /><img class='dingwei2' src='../../../images/delete1.png'>");
                };

                $(".dingwei2").live("click",function(){
                    $(this).prev().remove();
                    $(this).remove();
                });

                //检查是否添加关键字，关键字是否为空
                var checkKeyWord = function(){
                    var keywordlen=$('.dis input').size();
                    if(keywordlen<=0){
                        alert("请添加关键字!");
                        return false;
                    }
                    if(keywordlen>=1){
                        for(var i=0;i<keywordlen;i++){
                            if($('.dis input')[i].value==""){
                                return false;
                            }
                        }
                    }
                    return true;
                };

                $scope.searchButton1=function(){
                    if($('#starttime1').val()==""){
                        alert('开始时间不能为空!');
                        return false;
                    }
                    if($('#endtime1').val()==""){
                        alert('结束时间不能为空!');
                        return false;
                    }
                    if($('#starttime1').val()>$('#endtime1').val()){
                        alert('开始时间不能大于结束时间!');
                        return false;
                    }
                    setInitPage();
                    $scope.queryData1();
                };

                $scope.searchButton2=function(){
                    if($('#starttime2').val()==""){
                        alert('请选择开始时间!');
                        return false;
                    }
                    if($('#endtime2').val()==""){
                        alert('请选择结束时间!');
                        return false;
                    }
                    if($('#starttime1').val()>$('#endtime1').val()){
                        alert('开始时间不能大于结束时间!');
                        return false;
                    }
                    if(!checkKeyWord()){
                        alert('关键字不能为空!');
                        return false;
                    }
                    $scope.queryData2();
                };

                $scope.queryData1 = function(){
                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var engines = new Array()
                    var selects = $("input[type='checkbox'][name='engine']:checked");
                    for(var i =0;i<selects.length;i++){
                        engines[i] = selects[i].value;
                    }
                    var condition ={
                        starttime:$('#starttime1').val(),
                        endtime:$('#endtime1').val(),
                        keyword:$('#keyword').val(),
                        searchengine:engines,
                        pageindex:$scope.grid1.gridpagedata.nowpage,
                        pagesize:$scope.grid1.gridpagedata.pagesize
                    };

                    var f = getSearchKeyword(condition);

                    $.when(f).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });

                };

                var getCondition2 = function(){
                    var input = $('.dis input');
                    var keywords = new Array();
                    for(var i=0;i<input.length;i++)
                    {
                        keywords[i] = input[i].value;
                    }

                    var condition ={
                        starttime:$('#starttime2').val(),
                        endtime:$('#endtime2').val(),
                        keywords:keywords,
                        indicatetype:$scope.trend.value
                    };
                    return condition;
                };

                $scope.queryData2 = function(){
                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var condition = getCondition2();

                    var f1 = getKeyWordCompare(condition);
                    var f2 = getKeyWordTableTrend(condition);
                    var f3 = getKeyWordLineTrend(condition);
                    var f4= getKeyWordPie(condition);

                    $.when(f1,f2,f3,f4).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });

                };

                var setInitPage = function(){
                    $scope.grid1.gridpagedata.nowpage = 1;
                };

                $scope.selectQuery1 = function(value){
                    var num = value;
                    $scope.starttime1 = dateFormat(new Date(new Date().setDate(new Date().getDate() -num)),'yyyy-MM-dd');
                    $scope.endtime1 = dateFormat(new Date(new Date().setDate(new Date().getDate() -1)),'yyyy-MM-dd');

                    $('#starttime1').val($scope.starttime1);
                    $('#endtime1').val($scope.endtime1);

                    setInitPage();
                    $scope.queryData1();

                };

                $scope.selectQuery2 = function(value){
                    var num = value;
                    $scope.starttime2 = dateFormat(new Date(new Date().setDate(new Date().getDate() -num)),'yyyy-MM-dd');
                    $scope.endtime2 = dateFormat(new Date(new Date().setDate(new Date().getDate() -1)),'yyyy-MM-dd');;
                    if(!checkKeyWord()){
                        alert('关键字不能为空!');
                        return false;
                    }
                    $('#starttime2').val($scope.starttime2);
                    $('#endtime2').val($scope.endtime2);
                    $scope.queryData2();
                };

                $scope.selectTrend = function(e){
                    $scope.indicator = e.trend.name;
                    $scope.trend = e.trend;
                    var condition = getCondition2();

                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var f1 = getKeyWordTableTrend(condition);
                    var f2 = getKeyWordLineTrend(condition);

                    $.when(f1,f2).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                $scope.selectPct = function(e){
                    $scope.pct = e.pct;
                    var condition = getCondition2();
                    condition.indicatetype = $scope.pct.value;

                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var f= getKeyWordPie(condition);

                    $.when(f).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                $scope.turnPage1 = function(){
                    $scope.queryData1();
                };

                var getSearchKeyword = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetSearchKeyWordRank",JSON.stringify(postdata),function(result){
                        $scope.grid1.gridpagedata.totalcount = result.recordCount;
                        $scope.grid1.gridpagedata.totalpage = result.pageCount;
                        $scope.grid1.gridpagedata.startline = result.startLine;
                        $scope.grid1.gridpagedata.endline = result.endLine;
                        $scope.grid1.gridpagedata.datacount = result.dataCount;
                        $scope.grid1.griddata.data = result.datas;
                        $scope.$apply();
                    });
                };

                var getKeyWordCompare = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetKeyWordCompare",JSON.stringify(postdata),function(result){
                        $scope.grid2.griddata.data = result.datas;
                        $scope.$apply();
                    });
                };

                var getKeyWordTableTrend = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetKeyWordTableTrend",JSON.stringify(postdata),function(result){
                        $scope.grid3.griddata.colnames = result.colNames;
                        $scope.grid3.griddata.colmodel = result.colModel;
                        $scope.grid3.griddata.data = result.datas;
                        $scope.$apply();
                    });
                };

                var getKeyWordLineTrend = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetKeyWordLineTrend",JSON.stringify(postdata),function(result){
                        if (result.length != 0 && result != null) {
                            for (var i = 0; i < result.length; i++) {
                                result[i].xSeries = result[i].xSeries;
                                result[i].name = result[i].y1Series.label;
                                result[i].data = result[i].y1Series.values;
                            }
                            $scope.highchartline.chartdata.xAxis.categories = result[0].xSeries;
                            $scope.highchartline.chartdata.series = result;
                        }
                        else
                        {
                            $scope.highchartline.chartdata.series = [];
                        }
                        $scope.$apply();
                    });
                };

                var getKeyWordPie = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetKeyWordPie",JSON.stringify(postdata),function(result){
                        var length = result.length;
                        var type = postdata.indicatetype;
                        switch(length){
                            case 1:
                                var series = getPieSeries("占比:",type,result[0].data);
                                $scope.highchartpie0.chartdata.title.text = result[0].keyword;
                                $scope.highchartpie0.chartdata.series = series;

                                $scope.highchartpie1.chartdata.title.text = "";
                                $scope.highchartpie1.chartdata.series = [];
                                $scope.highchartpie2.chartdata.title.text = "";
                                $scope.highchartpie2.chartdata.series = [];
                                $scope.highchartpie3.chartdata.title.text = "";
                                $scope.highchartpie3.chartdata.series = [];

                                break;
                            case 2:
                                var series = getPieSeries("占比:",type,result[0].data);
                                $scope.highchartpie0.chartdata.title.text = result[0].keyword;
                                $scope.highchartpie0.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[1].data);
                                $scope.highchartpie1.chartdata.title.text = result[1].keyword;
                                $scope.highchartpie1.chartdata.series = series;

                                $scope.highchartpie2.chartdata.title.text = "";
                                $scope.highchartpie2.chartdata.series = [];
                                $scope.highchartpie3.chartdata.title.text = "";
                                $scope.highchartpie3.chartdata.series = [];

                                break;
                            case 3:
                                var series = getPieSeries("占比:",type,result[0].data);
                                $scope.highchartpie0.chartdata.title.text = result[0].keyword;
                                $scope.highchartpie0.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[1].data);
                                $scope.highchartpie1.chartdata.title.text = result[1].keyword;
                                $scope.highchartpie1.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[2].data);
                                $scope.highchartpie2.chartdata.title.text = result[2].keyword;
                                $scope.highchartpie2.chartdata.series = series;

                                $scope.highchartpie3.chartdata.title.text = "";
                                $scope.highchartpie3.chartdata.series = [];

                                break;
                            case 4:
                                var series = getPieSeries("占比:",type,result[0].data);
                                $scope.highchartpie0.chartdata.title.text = result[0].keyword;
                                $scope.highchartpie0.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[1].data);
                                $scope.highchartpie1.chartdata.title.text = result[1].keyword;
                                $scope.highchartpie1.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[2].data);
                                $scope.highchartpie2.chartdata.title.text = result[2].keyword;
                                $scope.highchartpie2.chartdata.series = series;

                                series = getPieSeries("占比:",type,result[3].data);
                                $scope.highchartpie3.chartdata.title.text = result[3].keyword;
                                $scope.highchartpie3.chartdata.series = series;
                                break;

                        }
                        $scope.$apply();
                    });
                };

                var getPieSeries = function(name,type,data){
                    var serieDatas=[];
                    if(data.length==0){
                        return [];
                    }
                    switch(type){
                        case type:"searchcount"
                            for(var i =0;i<data.length;i++){
                                var serieData={name:data[i].searchengine,y:data[i].searchcount};
                                serieDatas.push(serieData);
                            }
                            break;
                        case type:"usercount"
                            for(var i =0;i<data.length;i++){
                                var serieData={name:data[i].searchengine,y:data[i].usercount};
                                serieDatas.push(serieData);
                            }
                            break;
                        default:
                            break;
                    }

                    var series =[{name:name,data:serieDatas}];
                    return series;
                };

                //提交关键字排名下载任务
                $scope.exportdata = {
                    title: "导出数据",
                    ok: function () {
                        var value = $("input[type='radio'][name='export']:checked").val();
                        var limitvalue = value=="all"?"":$('#inputtop').val();
                        var engines = new Array()
                        var selects = $("input[type='checkbox'][name='engine']:checked");
                        for(var i =0;i<selects.length;i++){
                            engines[i] = selects[i].value;
                        }
                        var condition ={
                            mainmodule:"市场热点分析",
                            submodule:"网络热点分析",
                            appname:"搜索热点",
                            starttime:$('#starttime1').val(),
                            endtime:$('#endtime1').val(),
                            keyword:$('#keyword').val(),
                            searchengine:engines,
                            limit:limitvalue
                        };

                        var url = httpservice.serverurl + "script/MarketHotPoint/SubmitKeyWordRankDownloadTask";
                        submitDownloadTask(condition,url);
                        //$scope.exportKeyWordRank(condition);

                    },
                    cancel: function () {}
                };

                $scope.exportKeyWordRank = function(condition){
                    downloadAllKeywordRank(condition);
                };

                //提交关键字搜索趋势下载任务
                $scope.exportKeyWordTrend = function(){
                    var condition = getCondition2();
                    condition.mainmodule = "市场热点分析";
                    condition.submodule = "网络热点分析";
                    condition.appname = "走势分析";
                    var url = httpservice.serverurl + "script/MarketHotPoint/SubmitKeyWordTrendDownloadTask";
                    submitDownloadTask(condition,url);
                    //downloadKeyWordTrend(condition);
                };

                //提交下载任务
                var submitDownloadTask = function (postdata,posturl) {
                    $.ajax({
                        url: posturl,
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            if(result){
                                alert('提交下载任务成功!');
                            }
                            else{
                                alert("提交下载任务失败!");
                            }
                        },
                        error:function(xmlHttpRequest,textStatus){
                            alert("请求出错!");
                        },
                        complete:function(xmlHttpRequest,textStatus){

                        }
                    });
                };


                /*文件下载*/
                var downloadAllKeywordRank = function (postdata) {
                    return $.ajax({
                        url: httpservice.serverurl + "script/MarketHotPoint/UpLoadKeyWordRank",
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            var url = httpservice.serverurl + 'script/MarketHotPoint/DownLoadFile?fileId=' + result.FileId + '&fileName=' + result.FileName; //转向网页的地址;
                            window.open(url, '_self');
                        }
                    });
                };

                var downloadKeyWordTrend = function (postdata) {
                    return $.ajax({
                        url: httpservice.serverurl + "script/MarketHotPoint/UpLoadKeyWordTrend",
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            var url = httpservice.serverurl + 'script/MarketHotPoint/DownLoadFile?fileId=' + result.FileId + '&fileName=' + result.FileName; //转向网页的地址;
                            window.open(url, '_self');
                        }
                    });
                };

                $scope.init=function(){
                    $scope.$emit('loading', 'true');
                    var condition ={
                        starttime:$scope.starttime1,
                        endtime:$scope.endtime1,
                        pageindex:$scope.grid1.gridpagedata.nowpage,
                        pagesize:$scope.grid1.gridpagedata.pagesize
                    };

                    var f = getSearchKeyword(condition);

                    $.when(f).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

//                $scope.init();



            };

            var hotPointEntCtrl = function ($scope, httpservice){
//                $scope.starttime = dateFormat(defaultstarttime,'yyyy-MM-dd');
//                $scope.endtime = dateFormat(defaultendtime,'yyyy-MM-dd');

                $scope.selectitems=[
                    {value:"user_count",name:'用户数'},
                    {value:"total_len",name:'用户流量'},
                    {value:"request_count",name:'访问次数'}
                ];
                $scope.trend = $scope.selectitems[0];

                //删除下载文件
                $(".deletemodel").live("click",function(e){
                    var fileId = $(e.target).parent().attr("id");
                    if(confirm('你确定要删除该文件?')){
                        $.ajax({
                            url:httpservice.serverurl + "script/Common/DeleteTask",
                            type:"get",
                            data:{id:fileId},
                            dataType:"json",
                            success:function(result){
                                if(result.state){
                                    var condition = {
                                        mainmodule:"市场热点分析",
                                        submodule:"入口热点分析"
                                    }
                                    $scope.getDownloadList(condition);
                                    alert('删除成功!');
                                }
                                else{
                                    alert('删除失败!');
                                }
                            },
                            error:function(xmlHttpRequest,textStatus){
                                alert('请求出错!');
                            },
                            complete:function(xmlHttpRequest,textStatus){

                            }
                        });
                    }
                })

                var downloadoperate = function(cellvalue, options, rowObject){
                    var listprint = "<a class='viewmodel' href='javascript:'id='"+rowObject.id+"' title = '查看'><img src='../../../images/chakan.png' /></a>" +
                        "<a class='downloadmodel' style='margin: 0 15px;' href= '"+httpservice.downloadurl+""+rowObject.filename+".csv' target='_blank' id='"+rowObject.id+"' state='"+rowObject.status+"' title='下载'><img src='../../../images/download.png' /></a>" +
                        "<a class='deletemodel' href='javascript:' id='"+rowObject.id+"' state='"+rowObject.state+"' title='删除'><img src='../../../images/delete1.png' /></a>";
                    return listprint;
                };

                var getCondition = function(){
                    var checkBox = $('input[type="checkbox"][name="subservice"]:checked');
                    var subServiceType = [];
                    var tmpValue = [];
                    for(var i=0;i<checkBox.length;i++)
                    {
                        tmpValue[i] = checkBox[i].value;
                    }
                    for(var i=0;i<tmpValue.length;i++)
                    {
                        if(tmpValue[i]=="200062"){
                            tmpValue.push('1500021');
                            tmpValue.push('1500115');
                        }
                    }
                    subServiceType = tmpValue;

                    var condition ={
                        starttime:$('#starttime').val(),
                        endtime:$('#endtime').val(),
                        subServiceType:subServiceType,
                        indicatetype:$scope.trend.value
                    };
                    return condition;
                };

                $scope.selectQuery = function(value){
                    var num = value;
                    var startTime = dateFormat(new Date(new Date().setDate(new Date().getDate() -num)),'yyyy-MM-dd');
                    var endTime = dateFormat(new Date(new Date().setDate(new Date().getDate() -1)),'yyyy-MM-dd');;

                    $('#starttime').val(startTime);
                    $('#endtime').val(endTime);

                    $scope.$emit('loading', 'true');
                    var condition =getCondition();

                    var f1 = getSubService34GPct(condition);
                    var f2 = getSubServiceTrend(condition);

                    $.when(f1,f2).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                $scope.selectChange = function(e){
                    $scope.indicator = e.trend.name;
                    $scope.trend = e.trend;
                    var condition = getCondition();

                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var f = getSubServiceTrend(condition);

                    $.when(f).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                $scope.queryData = function(){
                    if($('#starttime').val()==""){
                        alert('开始时间不能为空!');
                        return false;
                    }
                    if($('#endtime').val()==""){
                        alert('结束时间不能为空!');
                        return false;
                    }
                    if($('#starttime').val() > $('#endtime').val()){
                        alert('开始时间不能大于结束时间!');
                        return false;
                    }

                    var checkLength = $('input[type="checkbox"][name="subservice"]:checked').length;
                    if(checkLength==0){
                        alert('请选择分析的业务!');
                        return false;
                    }

                    var condition = getCondition();

                    $scope.$emit('loading', 'true');
                    $scope.$apply();

                    var f1 = getSubService34GPct(condition);
                    var f2 = getSubServiceTrend(condition);

                    $.when(f1,f2).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                $scope.exportTop = function(){
                    var condition = getCondition();
                    condition.mainmodule = "市场热点分析";
                    condition.submodule = "入口热点分析";
                    condition.appname = "入口热点分析";
                    var url = httpservice.serverurl + "script/MarketHotPoint/SubmitSubService34GPctDownloadTask";
                    submitDownloadTask(condition,url);
                    //downloadSubService34GPct(condition);
                };

                $scope.exportBottom = function(){
                    var condition = getCondition();
                    condition.mainmodule = "市场热点分析";
                    condition.submodule = "入口热点分析";
                    condition.appname = "入口热点分析";
                    var url = httpservice.serverurl + "script/MarketHotPoint/SubmitSubServiceTrendDownloadTask";
                    submitDownloadTask(condition,url);
                    //downloadSubServiceTrend(condition);
                };

                /*文件下载*/
                var downloadSubService34GPct = function (postdata) {
                    return $.ajax({
                        url: httpservice.serverurl + "script/MarketHotPoint/UpLoadSubService34GPct",
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            var url = httpservice.serverurl + 'script/MarketHotPoint/DownLoadFile?fileId=' + result.FileId + '&fileName=' + result.FileName; //转向网页的地址;
                            window.open(url, '_self');
                        }
                    });
                };

                var downloadSubServiceTrend = function (postdata) {
                    return $.ajax({
                        url: httpservice.serverurl + "script/MarketHotPoint/UpLoadSubServiceTrend",
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            var url = httpservice.serverurl + 'script/MarketHotPoint/DownLoadFile?fileId=' + result.FileId + '&fileName=' + result.FileName; //转向网页的地址;
                            window.open(url, '_self');
                        }
                    });
                };

                var getSubService34GPct = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetSubService34GPct",JSON.stringify(postdata),function(result){
                        $scope.grid.griddata.data = result.datas;
                        $scope.$apply();
                    });
                };

                var getSubServiceTrend = function(postdata){
                    return httpservice.post("script/MarketHotPoint/GetSubServiceTrend",JSON.stringify(postdata),function(result){
                        var unit = "";
                        switch($scope.trend.value){
                            case 'user_count':
                                unit = '';
                                break;
                            case 'total_len':
                                unit = '(MB)';
                                break;
                            case 'request_count':
                                unit = '(次)';
                                break;
                            default:
                                break;
                        }

                        if (result.length != 0 && result != null) {
                            for (var i = 0; i < result.length; i++) {
                                result[i].xSeries = result[i].xSeries;
                                result[i].name = result[i].y1Series.label;
                                result[i].data = result[i].y1Series.values;
                            }
                            $scope.highchartline.chartdata.xAxis.categories = result[0].xSeries;
                            $scope.highchartline.chartdata.series = result;
                            $scope.highchartline.chartdata.tooltip.valueSuffix = unit;
                        }
                        else
                        {
                            $scope.highchartline.chartdata.series = [];
                        }
                        $scope.highchartline.chartdata.yAxis.title.text = $scope.trend.name;
                        $scope.$apply();
                    });
                };

                $scope.init=function(){
                    $scope.$emit('loading', 'true');
                    var subServiceType = new Array();
                    subServiceType[0] = 100009;
                    subServiceType[1] = 200062;
                    subServiceType[2] = 900003;

                    var condition ={
                        starttime:$('#starttime').val(),
                        endtime:$('#endtime').val(),
                        subServiceType:subServiceType,
                        indicatetype:$scope.trend.value
                    };

                    var f1 = getSubService34GPct(condition);
                    var f2 = getSubServiceTrend(condition);

                    $.when(f1,f2).then(function () {

                    }).always(function () {
                            $scope.$emit('loading', 'false');
                            $scope.$apply();
                        });
                };

                //$scope.init();

                $scope.grid = {
                    griddata: {
                        colnames: ['业务名称','总用户数','总流量(MB)','访问次数','人均流量(MB)','日均流量(MB)',"日均用户数","日均访问次数","3G用户占比","4G用户占比"],
                        colmodel: [
                            { name: 'subservice', index: 'subservice', sortable: false, align:"center"},
                            { name: 'usercount', index: 'usercount', sortable: false, align:"center",hidden:true},
                            { name: 'totallen', index: 'totallen', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'requestcount', index: 'requestcount', sortable: true, sorttype: 'number',align:"center"},
                            { name: 'userlen', index: 'userlen', sortable: true, sorttype: 'number', align:"center",hidden:true},
                            { name: 'daylen', index: 'daylen', sortable: true, sorttype: 'number',align:"center"},
                            { name: 'dayusercount', index: 'dayusercount', sortable: true, sorttype: 'number', align:"center"},
                            { name: 'dayrequestcount', index: 'dayrequestcount', sortable: true, sorttype: 'number', align:"center"},
                            { name: '_3gpct', index: '_3gpct', sortable: false, align:"center"},
                            { name: '_4gpct', index: '_4gpct', sortable: false, align:"center"}
                        ],
                        data: [
//                            { subservice: "微信",usercount: 1000, totallen: 1000, requestcount: 1000, userlen:1000, "daylen":1000, "dayusercount": 1000,dayrequestcount:1000,_3gpct:"40%", _4gpct:"40%"}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth($(window).width()-61);
                        grid.setGridHeight(100);
                    }
                };

                $scope.downloadList = {
                    gridpagedata:{
                        nowpage:1,
                        totalpage:1,
                        totalcount:20,
                        startline:1,
                        endline:20,
                        pagesize:20,
                        datacount:20,
                        pagelist:[20,50,100],
                        toFirstpage: function(){
                            $scope.downloadList1.gridpagedata.nowpage = 1;
                            $scope.turnPageWAPByType();
                        },
                        toToppage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage>1){
                                $scope.downloadList1.gridpagedata.nowpage--;
                            }
                            $scope.turnPageWAPByType();
                        },
                        toNextpage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage<$scope.downloadList1.gridpagedata.totalpage){
                                $scope.downloadList1.gridpagedata.nowpage++;
                            }
                            $scope.turnPageWAPByType();
                        },
                        toLastpage: function(){
                            $scope.downloadList1.gridpagedata.nowpage = $scope.downloadList1.gridpagedata.totalpage;
                            $scope.turnPageWAPByType();
                        },
                        topage: function(){
                            if($scope.downloadList1.gridpagedata.nowpage<1){
                                $scope.downloadList1.gridpagedata.nowpage = 1;
                            }
                            if($scope.downloadList1.gridpagedata.nowpage>$scope.downloadList1.gridpagedata.totalpage){
                                $scope.downloadList1.gridpagedata.nowpage = $scope.downloadList1.gridpagedata.totalpage;
                            }
                            $scope.turnPageWAPByType();
                        },
                        changePagesize: function(){
                            $scope.downloadList1.gridpagedata.nowpage = 1;
                            $scope.turnPageWAPByType();
                        }
                    },
                    griddata: {
                        colnames: ['ID','下载文件名', '创建时间','主模块','子模块','应用名称', '下载状态', '操作'],
                        colmodel: [
                            { name: 'id', index: 'id', sortable: false, align:"center",hidden:true },
                            { name: 'filename', index: 'filename', sortable: false, align:"center" },
                            { name: 'createtime', index: 'createtime', sortable: false, align:"center" },
                            { name: 'mainmodule',width:100, index: 'mainmodule', sortable: false, align:"center"},
                            { name: 'submodule',width:100, index: 'submodule', sortable: false, align:"center"},
                            { name: 'appname',width:100, index: 'appname', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'status',width:100, index: 'status', sortable: false,sorttype: 'number', align:"center"},
                            { name: 'operate', index: 'operate', sortable: false, align:"center",formatter:downloadoperate}
                        ],
                        data: [
                            { "filename": "微信", "mainmodule": 1000, "submodule":1000, "appname":1000, "createtime": 1000,"status":1000, "operate":1000}
                        ]
                    },
                    obj:{},
                    shrinkToFit:true,
                    gridresize: function (grid) {
                        grid.setGridWidth(800);
                        grid.setGridHeight(300);
                    }
                };

                $scope.dialogList={
                    title:"下载列表",
                    ok:function(){},
                    cancel:function(){}
                };

                $scope.showDownloadlist = function(){
                    $scope.dialogList.show();
                    var condition = {
                        mainmodule:"市场热点分析",
                        submodule:"入口热点分析"
                    }
                    $scope.getDownloadList(condition);
//                    setInterval(function(){
//                        $.ajax({
//                            url:httpservice.serverurl + "script/Common/GetTaskList",
//                            type:"post",
//                            data:JSON.stringify(condition),
//                            dataType:"json",
//                            success:function(result){
//                                $scope.downloadList.griddata.data = result.datas;
//                                $scope.$apply();
//                            },
//                            error:function(xmlHttpRequest,textStatus){
//                                alert("请求出错!");
//                            },
//                            complete:function(xmlhHttpRequest,textStatus){
//
//                            }
//                        });
//                    },500);
                }

                $scope.getDownloadList = function(postdata){
                    $.ajax({
                        url:httpservice.serverurl + "script/Common/GetTaskList",
                        type:"post",
                        data:JSON.stringify(postdata),
                        dataType:"json",
                        success:function(result){
                            $scope.downloadList.griddata.data = result.datas;
                            $scope.$apply();
                        },
                        error:function(xmlHttpRequest,textStatus){
                            alert("请求出错!");
                        },
                        complete:function(xmlhHttpRequest,textStatus){

                        }
                    });
                }

                //提交下载任务
                var submitDownloadTask = function (postdata,posturl) {
                    $.ajax({
                        url: posturl,
                        type: "POST",
                        data: JSON.stringify(postdata),
                        dataType: "json",
                        success: function (result, textStatus) {
                            if(result){
                                alert('提交下载任务成功!');
                            }
                            else{
                                alert("提交下载任务失败!");
                            }
                        },
                        error:function(xmlHttpRequest,textStatus){
                            alert("请求出错!");
                        },
                        complete:function(xmlHttpRequest,textStatus){

                        }
                    });
                };

                $scope.highchartline = {
                    chartdata: {
                        chart: {
                            height: 360,
                            type: 'line'
                        },
                        title: {
                            text: '走势分析图'
                        },
                        xAxis: {
                            gridLineWidth: 1,
                            lineColor: '#000',
                            tickColor: '#000',
                            labels: {
                                rotation: -30,
                                align: 'right',
                                style: {
                                    fontFamily: '黑体',
                                    fontWeight: 'Bold'           //Times New Roman
                                }
                            },
                            categories: ['2015.9.1','2015.9.2','2015.9.3','2015.9.4','2015.9.5','2015.9.6','2015.9.7','2015.9.8','2015.9.9','2015.9.10']
                        },
                        yAxis: {
                            minorTickInterval: 'auto',
                            lineColor: '#000',
                            lineWidth: 1,
                            tickWidth: 1,
                            tickColor: '#000',
                            title: {
                                text: '用户数'
                            }
                        },
                        plotOptions: {
                            series: {
                                showCheckbox: true,
                                selected: true
//                                point: {
//                                    events: {
//                                        click: function () {
//                                        }
//                                    }
//                                }
                            },
                            line: {
                                events: {
                                    checkboxClick: function (event) {
                                        if (event.checked == true) {
                                            this.show();
                                        }
                                        else {
                                            this.hide();
                                        }
                                    },
                                    legendItemClick: function (event) {//return false 即可禁用LegendIteml，防止通过点击item显示隐藏系列
                                        return false;
                                    }
                                }
                            }
                        },
                        tooltip: {
                            valueSuffix: '次'
                        },
                        exporting: {
                            enabled:false
                        },
                        credits: {
                            enabled:false
                        },
                        series: [
//                            {
//                                name: '微信',
//                                data: [5990,7667,6776,10554,7120,8476,4445,9692,12386,2962]
//                            }
                        ]
                    },
                    obj: {}
                };
            };

            angular.module('hotPointMarket-ctrl', [])
                .controller('HotPointNetCtrl', ['$scope', 'HttpService', hotPointNetCtrl])
                .controller('HotPointEntCtrl', ['$scope', 'HttpService', hotPointEntCtrl]);
        })(jQuery);
    }
});